package com.ruoyi.web.controller.cat;


import com.ruoyi.cat.domain.CatArticletaskTable;
import com.ruoyi.cat.domain.DTO.ExpensesDTO;
import com.ruoyi.cat.domain.DTO.FinanceDTO;
import com.ruoyi.cat.domain.VO.FinanceVO;
import com.ruoyi.cat.service.ICatTradedetailTableService;
import com.ruoyi.cat.service.ICatUserbasicTableService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "管理端-财务管理接口")
@RestController
@RequestMapping("/system/finance")
public class FinanceController extends BaseController {


    @Autowired
    private ICatTradedetailTableService iCatUserbasicTableService;

    @ApiOperation("财务管理列表")
    @GetMapping("/list")
    public TableDataInfo list(FinanceVO financeVO)
    {
        startPage();
        List<FinanceDTO> list = iCatUserbasicTableService.selectTable(financeVO);
        return getDataTable(list);
    }

    @ApiOperation("收入支出多少笔")
    @GetMapping("/IncomeExpenses")
    public AjaxResult IncomeExpenses(FinanceVO financeVO)
    {
        financeVO.setTradeType("0");
        ExpensesDTO expensesDTO = new ExpensesDTO();
        ExpensesDTO expensesDTO1 =  iCatUserbasicTableService.getTradeNumData(financeVO);
        if (expensesDTO1 != null) {
            expensesDTO.setEarning(expensesDTO1.getEarning());
            expensesDTO.setEarningPen(expensesDTO1.getEarningPen());
        }
        financeVO.setTradeType("1");
        ExpensesDTO expensesDTO2 =  iCatUserbasicTableService.getTradeNumData(financeVO);
        if (expensesDTO1 != null) {
            expensesDTO.setDisburse(expensesDTO2.getEarning());
            expensesDTO.setDisbursePen(expensesDTO2.getEarningPen());
        }
        return success(expensesDTO1);
    }

    @ApiOperation("获取折线图")
    @GetMapping("/getLineChart")
    public AjaxResult getLineChart(FinanceVO financeVO)
    {
        return success(iCatUserbasicTableService.getTradeNumGroupBy(financeVO));
    }




}
